//=============================================================================
/**
 * @file	fld_legend_demo.c
 * @brief	フィールド伝説系デモ
 * @author	Nozomu Saito
 *
 * モジュール名：FldLegDemo_
 *
 */
//=============================================================================

#include "common.h"

#include "system/arc_util.h"
#include "fieldmap.h"
#include "fieldmap_work.h"
#include "fieldsys.h"

#include "fieldmap_func.h"


#include "system/snd_tool.h"

#include "fld_demo.naix"

#include "fld_legend_demo.h"

#include "../fielddata/build_model/build_model_id.h"

#include "system/camera_move.h"

#include "fielddata/eventdata/zone_d40r0107evc.h"
#include "fielddata/eventdata/zone_d17r0110evc.h"

#include "fld_bmp.h"

#include "fld_leg_demo_def.h"


#define BELL_ANM_NUM	(3)
#define SONIC_ANM_NUM	(2)
#define MAP_SONIC_ANM_NUM	(1)

#define MAP_SONIC_MAX	(4)		//マップ付属音波最大数
#define RUGIA_MAP_SONIC_MAX	(2)		//ルギア　マップ付属音波最大数
#define HOUOU_MAP_SONIC_MAX	(4)		//ホウオウ　マップ付属音波最大数


#define EYES_ANM_NUM	(3)
#define MAP_BELL_ANM_NUM	(2)
#define SHINE_ANM_NUM	(3)

#define RUGIA_EFF_ANM_NUM	(2)

#define LEG_MONS_APP_YOFS_G	(APP_YOFS_GOLD*FX32_ONE)
#define LEG_MONS_DOWN_SPD_G	(DOWN_SPD_GOLD*FX32_ONE)
#define LEG_MONS_APP_YOFS_S	(APP_YOFS_SILVER*FX32_ONE)
#define LEG_MONS_DOWN_SPD_S	(DOWN_SPD_SILVER*FX32_ONE)

#define SHINE_FRAME	(55+10)			//アニメフレーム+ウェイト

#define HOUOU_SCRN_NUM	(6)
#define HOUOU_SCRN_BG_ANM_FRAME	(6)		//6フレでBG更新

#define FIRST_MOVE_CAM_PARAM_NO	(0)
#define LAST_MOVE_CAM_PARAM_NO	(3)
//ベル位置
#define FX_GOL_BELL1_POS_X		(GOL_BELL1_POS_X*FX32_ONE)
#define FX_GOL_BELL1_POS_Y		(GOL_BELL1_POS_Y*FX32_ONE)
#define FX_GOL_BELL1_POS_Z		(GOL_BELL1_POS_Z*FX32_ONE)

#define FX_GOL_BELL2_POS_X		(GOL_BELL2_POS_X*FX32_ONE)
#define FX_GOL_BELL2_POS_Y		(GOL_BELL2_POS_Y*FX32_ONE)
#define FX_GOL_BELL2_POS_Z		(GOL_BELL2_POS_Z*FX32_ONE)

#define FX_GOL_BELL3_POS_X		(GOL_BELL3_POS_X*FX32_ONE)
#define FX_GOL_BELL3_POS_Y		(GOL_BELL3_POS_Y*FX32_ONE)
#define FX_GOL_BELL3_POS_Z		(GOL_BELL3_POS_Z*FX32_ONE)

#define FX_GOL_BELL4_POS_X		(GOL_BELL4_POS_X*FX32_ONE)
#define FX_GOL_BELL4_POS_Y		(GOL_BELL4_POS_Y*FX32_ONE)
#define FX_GOL_BELL4_POS_Z		(GOL_BELL4_POS_Z*FX32_ONE)

//銀バージョン鈴2個
#define FX_SIL_BELL1_POS_X		(SIL_BELL1_POS_X*FX32_ONE)
#define FX_SIL_BELL1_POS_Y		(SIL_BELL1_POS_Y*FX32_ONE)
#define FX_SIL_BELL1_POS_Z		(SIL_BELL1_POS_Z*FX32_ONE)

#define FX_SIL_BELL2_POS_X		(SIL_BELL2_POS_X*FX32_ONE)
#define FX_SIL_BELL2_POS_Y		(SIL_BELL2_POS_Y*FX32_ONE)
#define FX_SIL_BELL2_POS_Z		(SIL_BELL2_POS_Z*FX32_ONE)


#ifdef PM_DEBUG
extern int DebugLegFldDemoFlg;
#endif


typedef struct HOUOU_WORK_tag
{
	NNSG2dScreenData *ScrnData1[HOUOU_SCRN_NUM];
	NNSG2dScreenData *ScrnData2[HOUOU_SCRN_NUM];
	void *BgArc1[HOUOU_SCRN_NUM];
	void *BgArc2[HOUOU_SCRN_NUM];
	u8 XOfs1;
	u8 XOfs2;
	u8 YOfs;
	u8 Frame;
	GF_BGL_INI * bgl;
	int ScrNo;
}HOUOU_WORK;

typedef struct RUGIA_WORK_tag
{
	FLD_3DOBJ_MDL	EffMdl;
	FLD_3DOBJ_ANM	EffAnm[RUGIA_EFF_ANM_NUM];
	FLD_3DOBJ		EffObj;
}RUGIA_WORK;

typedef struct DEMO_PARENT_WORK_tag
{
	FLDMAPFUNC_SYS *FldMapFuncSys;
	FLDMAPFUNC_WORK * Bell;
	CAM_MOV_CNT_PTR CamCntPtr;		//カメラ制御ポインタ
	VecFx32 OrgTarget;
	VecFx32 OrgCamPos;

	int Version;
}DEMO_PARENT_WORK;

typedef struct DEMO_AF_APP_PARENT_WORK_tag
{
	//カメラ情報
	fx32 Distance;
	CAMERA_ANGLE Angle;
	VecFx32 Shift;
	u16 PerspWay;
	u16 Version;
	fx32 Near;
	fx32 Far;
	CAM_MOV_CNT_PTR CamCntPtr;
}DEMO_AF_APP_PARENT_WORK;

typedef struct FLD_LEG_DEMO_WORK_tag
{
	NNSFndAllocator Allocator;
	u8 Seq;
	u8 MapSncVanish;
	u16 Version;

	FLD_3DOBJ_MDL	MdlBell;
	FLD_3DOBJ_MDL	MdlSnc;
	FLD_3DOBJ_MDL	MdlMapSnc;
	FLD_3DOBJ_ANM	AnmBell[BELL_ANM_NUM];
	FLD_3DOBJ_ANM	AnmSnc[SONIC_ANM_NUM];
	FLD_3DOBJ_ANM	AnmMapSnc;
	FLD_3DOBJ		ObjBell;
	FLD_3DOBJ		ObjSnc;
	FLD_3DOBJ		ObjMapSnc[MAP_SONIC_MAX];

	RUGIA_WORK		RugiaWork;
	HOUOU_WORK		HououWork;
	TCB_PTR			EffTcb;
	int BmObjID;

	const GF_CAMERA_PARAM	*CamParam;
	const VecFx32			*CamShift;
}FLD_LEG_DEMO_WORK;


//ルギア目アニメイベント用ワーク
typedef struct FLD_EYES_WORK_tag
{
	NNSFndAllocator Allocator;

	FLD_3DOBJ_MDL	MdlEyes;
	FLD_3DOBJ_ANM	AnmEyes[EYES_ANM_NUM];
	FLD_3DOBJ		ObjEyes;
	int Counter;
}FLD_EYES_WORK;

typedef struct FLD_DESCEND_WORK_tag
{
	fx32 Len;
	fx32 OrgY;
	u16 Wait;
	u16	Frame;

	NNSFndAllocator Allocator;

	FLD_3DOBJ_MDL	Mdl;
	FLD_3DOBJ_ANM	Anm[SHINE_ANM_NUM];
	FLD_3DOBJ		Obj;

	u16 Version;
	u16 WingSeMargine;
}FLD_DESCEND_WORK;

enum{
	SEQ_WAIT,
	SEQ_ANM_UP_START,
	SEQ_ANM_UP_END_CHK,
	SEQ_ANM_LOOP,
	SEQ_ANM_SONIC_START,
	SEQ_ANM_SONIC_END_CHK,
};

enum{
	SEQ_MAPBELL_ANM_INIT,
	SEQ_MAPBELL_ANM_LOOP_START,
	SEQ_MAPBELL_ANM_END,
};

const u8 HououBG1Arc[] = {
	NARC_fld_demo_hou_demobg1_1_nscr,
	NARC_fld_demo_hou_demobg1_2_nscr,
	NARC_fld_demo_hou_demobg1_3_nscr,
	NARC_fld_demo_hou_demobg1_4_nscr,
	NARC_fld_demo_hou_demobg1_5_nscr,
	NARC_fld_demo_hou_demobg1_6_nscr,
};

const u8 HououBG2Arc[] = {
	NARC_fld_demo_hou_demobg2_1_nscr,
	NARC_fld_demo_hou_demobg2_2_nscr,
	NARC_fld_demo_hou_demobg2_3_nscr,
	NARC_fld_demo_hou_demobg2_4_nscr,
	NARC_fld_demo_hou_demobg2_5_nscr,
	NARC_fld_demo_hou_demobg2_6_nscr,
};



static void SetupData(DEMO_PARENT_WORK *work);

static void DatBell_Create(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work);
static void DatBell_Delete(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work);
static void DatBell_Main(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work);
static void DatBell_Draw(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work);


static void ChangeBellAnm(FLD_LEG_DEMO_WORK *wk);

static void SetAnmFrame(FLD_3DOBJ_ANM *anm, const u8 inNum, const u32 inFrame);
static BOOL AnimeNoLoop(FLD_3DOBJ_ANM *anm, const u8 inNum);
static void AnimeLoop(FLD_3DOBJ_ANM *anm, const u8 inNum);
static void VisibleSonic(FLD_LEG_DEMO_WORK *wk, const BOOL inValid);


static void InitEyesGraphicData(const int inHeapID, FIELDSYS_WORK *fsys, FLD_EYES_WORK *outWork);
static void DelEyesGraphicData(FLD_EYES_WORK *outWork);
static BOOL EyesMoveEvt(GMEVENT_CONTROL * event);

static void StartBellResonance(FIELDSYS_WORK * fsys);
static BOOL	AnmLoopWaitEvt(GMEVENT_CONTROL * event);

static BOOL MapBellAnmEvt(GMEVENT_CONTROL * event);
static BOOL CamMoveWaitEvt(GMEVENT_CONTROL * event);
static BOOL DescendPokeEvt(GMEVENT_CONTROL * event);
static BOOL ReturnCameraEvt(GMEVENT_CONTROL * event);

static void StartWeatherEffectRugia(FIELDSYS_WORK * fsys);
static void StartWeatherEffectHouou(FIELDSYS_WORK * fsys);
static void EndWeatherEffectRugia(FLD_LEG_DEMO_WORK *wk);
static void EndWeatherEffectHouou(FLD_LEG_DEMO_WORK *wk);

static void RugiaEffectTcb(TCB_PTR tcb, void *work);
static void HououEffectTcb(TCB_PTR tcb, void *work);

static const FLDMAPFUNC_DATA BellData = {
	FLDMAP_PRI_LEG_DEMO_EFF,
	sizeof(FLD_LEG_DEMO_WORK),
	DatBell_Create,
	DatBell_Delete,
	DatBell_Main,
	DatBell_Draw,
};

static const GF_CAMERA_PARAM CameraDataRugia[] = {
	{
		0x29aec1,
		{ -0x201e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ルギア　左側鈴
	{
		0x29aec1,
		{ -0x201e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ルギア　右側鈴
	{
		0x29aec1,
		{ -0x210e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ルギア　自機
	{
		0x29aec1,
		{ -0x210e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ルギア　滝つぼ

	{
		0x29aec1,
		{ -0x210e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ルギア　アプリデモから戻ったとき
};

static const GF_CAMERA_PARAM CameraDataHouou[] = {
	{
		0x29aec1,
		{ -0xa9e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ホウオウ　左側鈴
	{
		0x29aec1,
		{ -0xa9e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},											//ホウオウ　右側鈴
	{
		0x29aec1,
		{ -0x89e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0x0cc1,
		0	//dummy
	},											//ホウオウ　自機
	{
		0x29aec1,
		{ -0x45e,0, 0 },
		GF_CAMERA_PERSPECTIV,
		0xcc1,
		0	//dummy
	},											//ホウオウ　そら
};

static const VecFx32 CameraShiftRugia[] = {
	{ -0x7f000, 0, -0xd0000 },
	{ 0x3f000, 0, -0xd0000 },
	{ 0, 0, -0x52000 },
	{ 0, 0, -0x1b1000 },
	{ 0, 0, -0xe1000 },
};

static const VecFx32 CameraShiftHouou[] = {
	{ -0xc3000, -0x949ae, -0x2d311 },
	{ 0xc6000, -0x949ae, -0x2d311 },
//	{ 0, -0x566f0, -0x3ee3d },
//	{ 0, 0x61910, -0x3ee3d },
	{ 0,-0x23c07, -0x170c3},
	{ 0,0x1efa1e,0x1cbae},
};


//==============================================================================
/**
 * デモ用フィールドワークの初期化
 *
 * @param	fsys			フィールドシステムポインタ
 *
 * @return	none
 */
//==============================================================================
void FldLegDemo_Init(FIELDSYS_WORK * fsys)
{
	int ver;
	DEMO_PARENT_WORK *work;
	//フィールド汎用ワークにメモリをアロケーション
	fsys->fldmap->Work = sys_AllocMemoryLo(HEAPID_FIELD, sizeof(DEMO_PARENT_WORK));
	work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;

	work->CamCntPtr = CamMove_Init(HEAPID_FIELD, fsys->camera_ptr);
	//ルギア・ホウオウどちらのデモかをセット(バージョンで判定)
	work->Version = CasetteVersion;
#ifdef PM_DEBUG
	if (DebugLegFldDemoFlg == 1){
		work->Version = VERSION_GOLD;
	}else if (DebugLegFldDemoFlg == 2){
		work->Version = VERSION_SILVER;
	}
#endif

	//カメラの注視点と位置を保存
	work->OrgTarget = GFC_GetLookTarget(fsys->camera_ptr);
	work->OrgCamPos = GFC_GetCameraPos(fsys->camera_ptr);

	work->FldMapFuncSys = fsys->fldmap->fmapfunc_sys;

	SetupData(work);
}

//==============================================================================
/**
 * デモ用フィールドワークの解放
 *
 * @param	fsys			フィールドシステムポインタ
 *
 * @return	none
 */
//==============================================================================
void FldLegDemo_End(FIELDSYS_WORK * fsys)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;

	//カメラコントローラ解放
	CamMove_Delete(work->CamCntPtr);
	//フィールド汎用ワークにメモリを解放
	sys_FreeMemoryEz(fsys->fldmap->Work);
	fsys->fldmap->Work = NULL;
}

//==============================================================================
/**
 * 鈴出現
 *
 * @param		fsys			フィールドシステムポインタ
 *
 * @return	none
 */
//==============================================================================
void FldLegDemo_AppearBell(FIELDSYS_WORK * fsys)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//鈴ワークにアクセス
	FLD_LEG_DEMO_WORK *demo_work = FLDMAPFUNC_GetFreeWork(work->Bell);
	//シーケンスを鈴上昇シーケンスへ
	demo_work->Seq = SEQ_ANM_UP_START;
}

//==============================================================================
/**
 * 鈴共鳴スタート
 *
 * @param	fsys			フィールドシステムポインタ
 * @param	inMapSncVanish	マップ共鳴鈴消すか？
 *
 * @return	none
 */
//==============================================================================
void FldLegDemo_StartBellResonance(FIELDSYS_WORK * fsys, const u8 inMapSncVanish)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//鈴ワークにアクセス
	FLD_LEG_DEMO_WORK *demo_work = FLDMAPFUNC_GetFreeWork(work->Bell);
	//現在アニメが動いているか？(シーケンスがループアニメシーケンスになっているか？)
	if ( demo_work->Seq != SEQ_ANM_LOOP ){
		GF_ASSERT_MSG(0,"共鳴コマンド呼ぶのがはやい。まだ、前の共鳴終わってない\n");
		//アニメ終了待ちイベントをコール
		FieldEvent_Call(fsys->event, AnmLoopWaitEvt, NULL);
	}else{
		demo_work->MapSncVanish = inMapSncVanish;
		//共鳴アニメ実行
		StartBellResonance(fsys);
	}
}

//==============================================================================
/**
 * マップ付属鈴光りだすイベント
 *
 * @param	fsys			フィールドシステムポインタ
 *
 * @return	none
 */
//==============================================================================
void FldLegDemo_StartMapBellAnm(FIELDSYS_WORK * fsys)
{
	//アニメ終了待ちイベントをコール
	FieldEvent_Call(fsys->event, MapBellAnmEvt, NULL);
}

//==============================================================================
/**
 * 鈴共鳴スタート
 *
 * @param	fsys			フィールドシステムポインタ
 *
 * @return	none
 */
//==============================================================================
static void StartBellResonance(FIELDSYS_WORK * fsys)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//鈴ワークにアクセス
	FLD_LEG_DEMO_WORK *demo_work = FLDMAPFUNC_GetFreeWork(work->Bell);
	//シーケンスを鈴上昇シーケンスへ
	demo_work->Seq = SEQ_ANM_SONIC_START;
}

//==============================================================================
/**
 * アニメループシーケンス突入待ちイベント
 *
 * @param	event		イベントポインタ
 *
 * @return	BOOL		TRUEで終了
 */
//==============================================================================
static BOOL	AnmLoopWaitEvt(GMEVENT_CONTROL * event)
{
	FIELDSYS_WORK * fsys = FieldEvent_GetFieldSysWork(event);
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//鈴ワークにアクセス
	FLD_LEG_DEMO_WORK *demo_work = FLDMAPFUNC_GetFreeWork(work->Bell);
	if (demo_work->Seq == SEQ_ANM_LOOP){
		//共鳴アニメ実行
		StartBellResonance(fsys);
		return TRUE;
	}

	return FALSE;
}

//==============================================================================
/**
 * ルギア目アニメーションイベントコール
 *
 * @param	fsys			フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_CallEyesEvt(FIELDSYS_WORK *fsys)
{
	FLD_EYES_WORK *few;
	few = sys_AllocMemoryLo(HEAPID_FIELD, sizeof(FLD_EYES_WORK));
	few->Counter = 0;

	//初期化
	InitEyesGraphicData( HEAPID_FIELD, fsys, few );
	//イベントコール
	FieldEvent_Call(fsys->event, EyesMoveEvt, few);
}

#if 0
#ifdef PM_DEBUG

//==============================================================================
/**
 * ルギア目アニメーションイベントセット（デバッグ）
 *
 * @param	fsys			フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void DBG_FldLegDemo_SetEyesEvt(FIELDSYS_WORK *fsys)
{
	FLD_EYES_WORK *few;
	few = sys_AllocMemoryLo(HEAPID_FIELD, sizeof(FLD_EYES_WORK));

	//初期化
	InitEyesGraphicData( HEAPID_FIELD, fsys, few );
	//イベントセット
	FieldEvent_Set(fsys, EyesMoveEvt, few);
}

#endif
#endif

//==============================================================================
/**
 * ルギアデモで使用する素材のセットアップ
 *
 * @param	work		ワークポインタ
 *
 * @return	none
 */
//==============================================================================
static void SetupData(DEMO_PARENT_WORK *work)
{
	//鈴・音波
	work->Bell = FLDMAPFUNC_Create(work->FldMapFuncSys, &BellData);
}

//--海鳴りの鈴

//==============================================================================
/**
 * 鈴タスククリエイト関数　ワーク初期化
 *
 * @param	*fwk		フィールドマップファンクションポインタ
 * @param	*fsys		フィールドシステムポインタ
 * @param	*work		ワーク
 *
 * @retval  none
 */
//==============================================================================
static void DatBell_Create(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work)
{
	u8 i;
	int heap = HEAPID_FIELD;
	DEMO_PARENT_WORK *parent = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	FLD_LEG_DEMO_WORK *wk = (FLD_LEG_DEMO_WORK*)work;

	//バージョンセット
	wk->Version = parent->Version;
	// アロケーター作成
	sys_InitAllocator( &wk->Allocator, heap, 32 );

	//鈴モデルロード
	FLD_3DObjMdlLoad(&wk->MdlBell,ARC_FLD_DEMO_GRA , NARC_fld_demo_demolight_1_nsbmd, heap);
	//鈴+音波モデルロード
	FLD_3DObjMdlLoad(&wk->MdlSnc,ARC_FLD_DEMO_GRA , NARC_fld_demo_demolight_2_nsbmd, heap);

	//マップ付属鈴用音波モデルロード
	FLD_3DObjMdlLoad(&wk->MdlMapSnc,ARC_FLD_DEMO_GRA , NARC_fld_demo_demolight_2_2_nsbmd, heap);

	//アニメデータロード
	FLD_3DObjAnmLoad(&wk->AnmBell[0],&wk->MdlBell,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_1_nsbca,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&wk->AnmBell[1],&wk->MdlBell,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_1_nsbtp,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&wk->AnmBell[2],&wk->MdlBell,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_1_nsbta,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&wk->AnmSnc[0],&wk->MdlSnc,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_2_nsbca,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&wk->AnmSnc[1],&wk->MdlSnc,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_2_nsbta,
		heap, &wk->Allocator );

	FLD_3DObjAnmLoad(&wk->AnmMapSnc,&wk->MdlMapSnc,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_2_2_nsbta,
		heap, &wk->Allocator );

	//描画オブジェクト初期化
	FLD_3DObjInit( &wk->ObjBell, &wk->MdlBell );
	FLD_3DObjInit( &wk->ObjSnc, &wk->MdlSnc );
	//アニメをリンク
	FLD_3DObjAddAnm( &wk->ObjBell, &wk->AnmBell[0] );
	FLD_3DObjAddAnm( &wk->ObjBell, &wk->AnmBell[1] );
	FLD_3DObjAddAnm( &wk->ObjBell, &wk->AnmBell[2] );
	FLD_3DObjAddAnm( &wk->ObjSnc, &wk->AnmSnc[0] );
	FLD_3DObjAddAnm( &wk->ObjSnc, &wk->AnmSnc[1] );
	//描画フラグ設定	(非表示)
	FLD_3DObjSetDraw( &wk->ObjBell, FALSE );
	FLD_3DObjSetDraw( &wk->ObjSnc, FALSE );

	for (i=0;i<MAP_SONIC_MAX;i++){
		//描画オブジェクト初期化
		FLD_3DObjInit( &wk->ObjMapSnc[i], &wk->MdlMapSnc );
		//アニメをリンク
		FLD_3DObjAddAnm( &wk->ObjMapSnc[i], &wk->AnmMapSnc );
		//描画フラグ設定	(非表示)
		FLD_3DObjSetDraw( &wk->ObjMapSnc[i], FALSE );
	}

	//フレームセット
	SetAnmFrame(wk->AnmBell, BELL_ANM_NUM, 0);
	SetAnmFrame(wk->AnmSnc, SONIC_ANM_NUM, 0);
	SetAnmFrame(&wk->AnmMapSnc, MAP_SONIC_ANM_NUM, 0);

	//バージョン分岐
	{
		VecFx32 vec;
		//主人公の位置に表示
		FieldOBJ_VecPosGet( Player_FieldOBJGet( fsys->player ), &vec );
		FLD_3DObjSetMatrix( &wk->ObjBell, vec.x, vec.y, vec.z );
		FLD_3DObjSetMatrix( &wk->ObjSnc, vec.x, vec.y, vec.z );
		//ルギア・ホウオウで数と位置異なる
		if ( wk->Version == VERSION_SILVER ){				//銀バージョン
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[0],
								vec.x+(FX_SIL_BELL1_POS_X),
								vec.y+(FX_SIL_BELL1_POS_Y),
								vec.z+(FX_SIL_BELL1_POS_Z) );
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[1],
								vec.x+(FX_SIL_BELL2_POS_X),
								vec.y+(FX_SIL_BELL2_POS_Y),
								vec.z+(FX_SIL_BELL2_POS_Z) );
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[2], 0, 0, 0 );		//<<銀では未使用
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[3], 0, 0, 0 );		//<<銀では未使用

			//マップ依存鈴モデル
			wk->BmObjID = BMID_FIELD_OBJ_LGSZ;
			//カメラデータセット
			wk->CamParam = CameraDataRugia;
			wk->CamShift = CameraShiftRugia;
		}else{												//金バージョン
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[0],
								vec.x+(FX_GOL_BELL1_POS_X),
								vec.y+(FX_GOL_BELL1_POS_Y),
								vec.z+(FX_GOL_BELL1_POS_Z) );
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[1],
								vec.x+(FX_GOL_BELL2_POS_X),
								vec.y+(FX_GOL_BELL2_POS_Y),
								vec.z+(FX_GOL_BELL2_POS_Z) );
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[2],
								vec.x+(FX_GOL_BELL3_POS_X),
								vec.y+(FX_GOL_BELL3_POS_Y),
								vec.z+(FX_GOL_BELL3_POS_Z) );
			FLD_3DObjSetMatrix( &wk->ObjMapSnc[3],
								vec.x+(FX_GOL_BELL4_POS_X),
								vec.y+(FX_GOL_BELL4_POS_Y),
								vec.z+(FX_GOL_BELL4_POS_Z) );

			//マップ依存鈴モデル
			wk->BmObjID = BMID_FIELD_OBJ_HOSZ;
			//カメラデータセット
			wk->CamParam = CameraDataHouou;
			wk->CamShift = CameraShiftHouou;
		}
	}

	//シーケンスセット
	wk->Seq = SEQ_WAIT;

}

//==============================================================================
/**
 * 海鳴りの鈴タスクデリート関数
 *
 * @param	*fwk		フィールドマップファンクションポインタ
 * @param	*fsys		フィールドシステムポインタ
 * @param	*work		ワーク
 *
 * @retval  none
 */
//==============================================================================
static void DatBell_Delete(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work)
{
	FLD_LEG_DEMO_WORK *wk = (FLD_LEG_DEMO_WORK*)work;
	//アニメデータ破棄
	FLD_3DObjAnmDelete( &wk->AnmBell[2], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmBell[1], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmBell[0], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmSnc[1], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmSnc[0], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmMapSnc, &wk->Allocator);
	//モデルデータ破棄
	FLD_3DObjMdlDelete( &wk->MdlBell);
	FLD_3DObjMdlDelete( &wk->MdlSnc);
	FLD_3DObjMdlDelete( &wk->MdlMapSnc);
}

//==============================================================================
/**
 * 海鳴りの鈴タスクメイン関数
 *
 * @param	*fwk		フィールドマップファンクションポインタ
 * @param	*fsys		フィールドシステムポインタ
 * @param	*work		ワーク
 *
 * @retval  none
 */
//==============================================================================
static void DatBell_Main(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work)
{
	FLD_LEG_DEMO_WORK *wk = (FLD_LEG_DEMO_WORK*)work;
	switch(wk->Seq){
	case SEQ_WAIT:
		break;
	case SEQ_ANM_UP_START:
		//鈴表示
		FLD_3DObjSetDraw( &wk->ObjBell,TRUE );
		//上昇アニメスタート
		wk->Seq = SEQ_ANM_UP_END_CHK;
		break;
	case SEQ_ANM_UP_END_CHK:
		if ( AnimeNoLoop( wk->AnmBell, BELL_ANM_NUM ) ){
			//上昇アニメ終了。アニメ切り替え
			OS_Printf("上昇終了\n");
			ChangeBellAnm(wk);
			wk->Seq = SEQ_ANM_LOOP;
		}
		break;
	case SEQ_ANM_LOOP:		//通常状態アニメループ
		AnimeLoop( wk->AnmBell, BELL_ANM_NUM );
		break;
	case SEQ_ANM_SONIC_START:
		{
			//鈴非表示
			FLD_3DObjSetDraw( &wk->ObjBell, FALSE );
			//音波表示
			VisibleSonic(wk, TRUE);
			//音波フレームセット
			SetAnmFrame(wk->AnmSnc, SONIC_ANM_NUM, 0);
			SetAnmFrame(&wk->AnmMapSnc, MAP_SONIC_ANM_NUM, 0);
			//音波アニメスタート
			wk->Seq = SEQ_ANM_SONIC_END_CHK;
		}
		break;
	case SEQ_ANM_SONIC_END_CHK:
		AnimeLoop( wk->AnmBell, BELL_ANM_NUM );	//非表示だけど同期のためにアニメだけはさせておく
		AnimeNoLoop( &wk->AnmMapSnc, MAP_SONIC_ANM_NUM );
		if ( AnimeNoLoop( wk->AnmSnc, SONIC_ANM_NUM ) ){ //音波アニメ終了
			//音波非表示
			VisibleSonic(wk, FALSE);
			//鈴表示
			FLD_3DObjSetDraw( &wk->ObjBell, TRUE );
			wk->Seq = SEQ_ANM_LOOP;
		}
		break;
	}
}

//==============================================================================
/**
 * 鈴タスクドロー関数
 *
 * @param	*fwk		フィールドマップファンクションポインタ
 * @param	*fsys		フィールドシステムポインタ
 * @param	*work		ワーク
 *
 * @retval  none
 */
//==============================================================================
static void DatBell_Draw(FLDMAPFUNC_WORK * fwk, FIELDSYS_WORK * fsys, void * work)
{
	u8 i;
	FLD_LEG_DEMO_WORK *wk = (FLD_LEG_DEMO_WORK*)work;

	FLD_3DObjDraw( &wk->ObjBell );
	FLD_3DObjDraw( &wk->ObjSnc );
	for(i=0;i<MAP_SONIC_MAX;i++){
		FLD_3DObjDraw( &wk->ObjMapSnc[i] );
	}
}

//==============================================================================
/**
 * 鈴アニメ切り替え
 *
 * @param	wk			ワークポインタ
 *
 * @retval  none
 */
//==============================================================================
static void ChangeBellAnm(FLD_LEG_DEMO_WORK *wk)
{
	int heap = HEAPID_FIELD;
	//アニメリムーブ
	FLD_3DObjRemoveAnm( &wk->ObjBell, &wk->AnmBell[0] );
	FLD_3DObjRemoveAnm( &wk->ObjBell, &wk->AnmBell[1] );
	FLD_3DObjRemoveAnm( &wk->ObjBell, &wk->AnmBell[2] );

	//アニメデータ破棄
	FLD_3DObjAnmDelete( &wk->AnmBell[2], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmBell[1], &wk->Allocator);
	FLD_3DObjAnmDelete( &wk->AnmBell[0], &wk->Allocator);

	//アニメデータロード
	FLD_3DObjAnmLoad(&wk->AnmBell[0],&wk->MdlBell,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_1_2_nsbca,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&wk->AnmBell[1],&wk->MdlBell,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_1_2_nsbtp,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&wk->AnmBell[2],&wk->MdlBell,ARC_FLD_DEMO_GRA,NARC_fld_demo_demolight_1_2_nsbta,
		heap, &wk->Allocator );

	//アニメをリンク
	FLD_3DObjAddAnm( &wk->ObjBell, &wk->AnmBell[0] );
	FLD_3DObjAddAnm( &wk->ObjBell, &wk->AnmBell[1] );
	FLD_3DObjAddAnm( &wk->ObjBell, &wk->AnmBell[2] );

	//フレームセット
	SetAnmFrame(wk->AnmBell, BELL_ANM_NUM, 0);
}

//==============================================================================
/**
 * アニメフレームセット
 *
 * @param	anm			アニメポインタ配列
 * @param	inNum		アニメ数
 * @param	inFrame		フレーム
 *
 * @retval  none
 */
//==============================================================================
static void SetAnmFrame(FLD_3DOBJ_ANM *anm, const u8 inNum, const u32 inFrame)
{
	u8 i;
	for (i=0;i<inNum;i++){
		FLD_3DObjAnmSet( &anm[i], inFrame  );
	}
}

//==============================================================================
/**
 * アニメフレーム更新関数
 *
 * @param	anm			アニメポインタ配列
 * @param	inNum		アニメ数
 *
 * @retval  BOOL		TRUE：アニメ終了	FALSE：アニメ継続
 */
//==============================================================================
static BOOL AnimeNoLoop(FLD_3DOBJ_ANM *anm, const u8 inNum)
{
	u8 i;
	BOOL end;
	u8 end_num = 0;
	for (i=0;i<inNum;i++){
		end = FLD_3DObjAnmNoLoop( &anm[i], FX32_ONE );
		if (end){
			OS_Printf("%d:アニメ終了\n",i);
			end_num++;
		}
	}
	if (end_num == inNum){
		return TRUE;
	}

	return FALSE;
}

//==============================================================================
/**
 * アニメフレーム更新関数
 *
 * @param	anm			アニメポインタ配列
 * @param	inNum		アニメ数
 *
 * @retval  none
 */
//==============================================================================
static void AnimeLoop(FLD_3DOBJ_ANM *anm, const u8 inNum)
{
	u8 i;
	for (i=0;i<inNum;i++){
		FLD_3DObjAnmLoop( &anm[i], FX32_ONE );
	}
}

//==============================================================================
/**
 * 音波表示状態コントロール
 *
 * @param	wk			ワークポインタ
 * @param	inValid		有効無効フラグ
 *
 * @retval  none
 */
//==============================================================================
static void VisibleSonic(FLD_LEG_DEMO_WORK *wk, const BOOL inValid)
{
	u8 i;
	u8 num;
	//ルギアホウオウで、使用する音波数が変わる
	if (wk->Version == VERSION_SILVER){
		num = RUGIA_MAP_SONIC_MAX;
	}else{
		num = HOUOU_MAP_SONIC_MAX;
	}

	FLD_3DObjSetDraw( &wk->ObjSnc, inValid );

	if (!wk->MapSncVanish){
		for (i=0;i<num;i++){
			FLD_3DObjSetDraw( &wk->ObjMapSnc[i], inValid );
		}
	}
}


//==============================================================================
/**
 * ルギア目グラフィックデータ初期化
 *
 * @param	inHeapID		ヒープID
 * @param	fsys			フィールドシステムポインタ
 * @param	outWork			ワークポインタ
 *
 * @retval  none
 */
//==============================================================================
static void InitEyesGraphicData(const int inHeapID, FIELDSYS_WORK *fsys, FLD_EYES_WORK *outWork)
{
	// アロケーター作成
	sys_InitAllocator( &outWork->Allocator, inHeapID, 32 );

	//モデルロード
	FLD_3DObjMdlLoad(&outWork->MdlEyes, ARC_FLD_DEMO_GRA , NARC_fld_demo_demoeye_nsbmd, inHeapID);

	//アニメデータロード
	FLD_3DObjAnmLoad(&outWork->AnmEyes[0], &outWork->MdlEyes, ARC_FLD_DEMO_GRA, NARC_fld_demo_demoeye_nsbma,
		inHeapID, &outWork->Allocator );
	FLD_3DObjAnmLoad(&outWork->AnmEyes[1], &outWork->MdlEyes, ARC_FLD_DEMO_GRA, NARC_fld_demo_demoeye_nsbtp,
		inHeapID, &outWork->Allocator );
	FLD_3DObjAnmLoad(&outWork->AnmEyes[2], &outWork->MdlEyes, ARC_FLD_DEMO_GRA, NARC_fld_demo_demoeye_nsbca,
		inHeapID, &outWork->Allocator );


	//描画オブジェクト初期化
	FLD_3DObjInit( &outWork->ObjEyes, &outWork->MdlEyes );

	//アニメをリンク
	FLD_3DObjAddAnm( &outWork->ObjEyes, &outWork->AnmEyes[0] );
	FLD_3DObjAddAnm( &outWork->ObjEyes, &outWork->AnmEyes[1] );
	FLD_3DObjAddAnm( &outWork->ObjEyes, &outWork->AnmEyes[2] );

	//フレームセット
	SetAnmFrame(outWork->AnmEyes, EYES_ANM_NUM, 0);

	//座標セット
	{
		VecFx32 vec;
		FieldOBJ_VecPosGet( Player_FieldOBJGet( fsys->player ), &vec );
		vec.x += (EYE_POS_X*FX32_ONE);
		vec.y += (EYE_POS_Y*FX32_ONE);
		vec.z += (EYE_POS_Z*FX32_ONE);
		FLD_3DObjSetMatrix( &outWork->ObjEyes, vec.x, vec.y, vec.z );
	}

	//描画フラグ設定	(表示)
	FLD_3DObjSetDraw( &outWork->ObjEyes, TRUE );
}

//==============================================================================
/**
 * ルギア目アニメデータ削除
 *
 * @param	outWork		ワークポインタ
 *
 * @retval 	none
 */
//==============================================================================
static void DelEyesGraphicData(FLD_EYES_WORK *outWork)
{
	//アニメデータ破棄
	FLD_3DObjAnmDelete( &outWork->AnmEyes[2], &outWork->Allocator);
	FLD_3DObjAnmDelete( &outWork->AnmEyes[1], &outWork->Allocator);
	FLD_3DObjAnmDelete( &outWork->AnmEyes[0], &outWork->Allocator);
	//モデルデータ破棄
	FLD_3DObjMdlDelete( &outWork->MdlEyes);
}

//==============================================================================
/**
 * ルギア目アニメイベント
 *
 * @param	event		イベントポインタ
 *
 * @retval  BOOL		TRUE：イベント終了	FALSE：イベント継続
 */
//==============================================================================
static BOOL EyesMoveEvt(GMEVENT_CONTROL * event)
{
	FLD_EYES_WORK * few = FieldEvent_GetSpecialWork(event);
	int *seq = FieldEvent_GetSeqWork(event);
	switch(*seq){
	case 0:		//アニメ終了監視
		few->Counter++;
		if (few->Counter == EYE_SE_START){
			Snd_SePlay(SEQ_SE_GS_RUGIA_MENOHIKARI);
		}

		if ( AnimeNoLoop( few->AnmEyes, EYES_ANM_NUM ) ){
			(*seq)++;
		}
		//描画
		FLD_3DObjDraw( &few->ObjEyes );
		break;
	case 1:		//終了
		DelEyesGraphicData(few);
		sys_FreeMemoryEz(few);
		return TRUE;
	}
	return FALSE;
}

//==============================================================================
/**
 * マップ付属鈴アニメイベント
 *
 * @param	event		イベントポインタ
 *
 * @retval  BOOL		TRUE：イベント終了	FALSE：イベント継続
 */
//==============================================================================
static BOOL MapBellAnmEvt(GMEVENT_CONTROL * event)
{
	u8 i;
	FIELDSYS_WORK * fsys = FieldEvent_GetFieldSysWork(event);
	int *seq = FieldEvent_GetSeqWork(event);

	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//ワークにアクセス
	FLD_LEG_DEMO_WORK *wk = FLDMAPFUNC_GetFreeWork(work->Bell);

	switch(*seq){
	case SEQ_MAPBELL_ANM_INIT:
		{
			F_OBJ_DATA	*f_obj;
			FLD_3D_ANM_DAT_PTR anm_dat;
			//ＯＢＪ取得
			f_obj = F_RES_OBJ_GetRenderObjPtr(fsys->FldResObjMng, wk->BmObjID);
			//アニメ
			for(i=0;i<MAP_BELL_ANM_NUM;i++){
				F3DA_SetFld3DAnime(	wk->BmObjID,
									i,
									TRUE,
									&f_obj->RenderObj,
									fsys->field_3d_anime);
			}

			for (i=0;i<MAP_BELL_ANM_NUM;i++){
				anm_dat = F3DA_GetFld3DAnmPtr( wk->BmObjID, i, fsys->field_3d_anime);
				//アニメの頭だしとループ数を設定
				F3DA_SetAnimeLoopMax(anm_dat, 1);
				F3DA_SetStartFrame(anm_dat);
			}
		}

		(*seq) = SEQ_MAPBELL_ANM_LOOP_START;
		break;
	case SEQ_MAPBELL_ANM_LOOP_START:			//光出しアニメ終了待ち
		{
			F_OBJ_DATA	*f_obj;
			FLD_3D_ANM_DAT_PTR anm_dat;
			//ＯＢＪ取得
			f_obj = F_RES_OBJ_GetRenderObjPtr(fsys->FldResObjMng, wk->BmObjID);
			//アニメ
			anm_dat = F3DA_GetFld3DAnmPtr( wk->BmObjID, 0, fsys->field_3d_anime);
			if ( F3DA_IsAnimeEnd(anm_dat) ){
				OS_Printf("1ループアニメ終了\n");

				//アニメパージ
				for(i=0;i<MAP_BELL_ANM_NUM;i++){
					F3DA_RemoveFld3DAnime(	fsys->field_3d_anime,
											&f_obj->RenderObj,
											wk->BmObjID,
											i	);
				}
				//ループアニメセット
				for(i=0;i<MAP_BELL_ANM_NUM;i++){
					F3DA_SetFld3DAnime(	wk->BmObjID,
										MAP_BELL_ANM_NUM+i,
										TRUE,
										&f_obj->RenderObj,
										fsys->field_3d_anime);
				}
				(*seq) = SEQ_MAPBELL_ANM_END;
			}
		}
		break;
	case SEQ_MAPBELL_ANM_END:
		return TRUE;
	}

	return FALSE;

}

//==============================================================================
/**
 * カメラセット
 *
 * @param	fsys		フィールドシステムポインタ
 * @param	inNo		デモカメラナンバー
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_SetCamera(FIELDSYS_WORK * fsys, const u8 inNo)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//ワークにアクセス
	FLD_LEG_DEMO_WORK *wk = FLDMAPFUNC_GetFreeWork(work->Bell);

	OS_Printf("camera_no = %d\n",inNo);

	GF_ASSERT(inNo < 3);

	//動かした注視点とカメラ位置を一度戻す
	GFC_SetLookTarget(&work->OrgTarget, fsys->camera_ptr);
	GFC_SetCameraPos(&work->OrgCamPos, fsys->camera_ptr);

	//距離
	GFC_SetCameraDistance(wk->CamParam[inNo].Distance, fsys->camera_ptr);
	//アングル変更
	GFC_SetCameraAngleRev(&wk->CamParam[inNo].Angle, fsys->camera_ptr);
	//パース変更
	GFC_SetCameraPerspWay(wk->CamParam[inNo].PerspWay, fsys->camera_ptr);

	//シフト
	GFC_ShiftCamera( &wk->CamShift[inNo], fsys->camera_ptr);

	//ニア・ファー
	GFC_SetCameraClip(150*FX32_ONE, 1700*FX32_ONE, fsys->camera_ptr);
	//カメラ情報をデバッグ出力
		{
			VecFx32 look_at = GFC_GetLookTarget(fsys->camera_ptr);
			const VecFx32 *bind = GFC_GetBindTargetVecPtr(fsys->camera_ptr);
			CAMERA_ANGLE ang = GFC_GetCameraAngle(fsys->camera_ptr);
			OS_Printf("dis:%x\n",GFC_GetCameraDistance(fsys->camera_ptr));
			OS_Printf("ang:%x,%x,%x\n",ang.x, ang.y, ang.z);
			OS_Printf("per:%x\n",GFC_GetCameraPerspWay(fsys->camera_ptr));
			OS_Printf("near_far:%d,%d\n",
					GFC_GetCameraNear(fsys->camera_ptr)/FX32_ONE, GFC_GetCameraFar(fsys->camera_ptr)/FX32_ONE);
			OS_Printf("shift:%x,%x,%x\n",look_at.x-bind->x, look_at.y-bind->y, look_at.z-bind->z);
		}
}

//==============================================================================
/**
 * カメラ移動	(ルギア時は滝　ホウオウ時は空)
 *
 * @param	fsys	フィールドシステムポインタ
 * @param	inNo	移動ナンバー 0 or 1
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_MoveCamera(FIELDSYS_WORK * fsys, const u8 inNo)
{
	int sync;
	u8 cam_no;
	CAMERA_MOVE_PARAM param;
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//ワークにアクセス
	FLD_LEG_DEMO_WORK *wk = FLDMAPFUNC_GetFreeWork(work->Bell);

	if (inNo == 0){
		cam_no = FIRST_MOVE_CAM_PARAM_NO;	//初めて移動
	}else{
		cam_no = LAST_MOVE_CAM_PARAM_NO;//ラスト移動
	}
	param.Angle = wk->CamParam[cam_no].Angle.x;
	param.PerspWay = wk->CamParam[cam_no].PerspWay;
	param.Length = wk->CamShift[cam_no];
	param.Distance = wk->CamParam[cam_no].Distance;
	//金銀で分岐
	if (work->Version == VERSION_GOLD){
		if (inNo == 0){
			sync = DEMO_CAM_FIRST_MOVE_SYNC_GOLD;	//初めて移動
		}else{
			sync = DEMO_CAM_LAST_MOVE_SYNC_GOLD;	//ラスト移動
		}
	}else{
		if (inNo == 0){
			sync = DEMO_CAM_FIRST_MOVE_SYNC_SILVER;	//初めて移動
		}else{
			sync = DEMO_CAM_LAST_MOVE_SYNC_SILVER;	//ラスト移動
		}
	}

	CamMove_Request(work->CamCntPtr, &param, sync);
}

//==============================================================================
/**
 * カメラ移動終了i監視イベントコール	(ルギア時は滝　ホウオウ時は空)
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_MoveCameraWait(FIELDSYS_WORK * fsys)
{
	FieldEvent_Call(fsys->event, CamMoveWaitEvt, NULL);
}

//==============================================================================
/**
 * カメラ移動終了監視イベントコール	(ルギア時は滝　ホウオウ時は空)
 *
 * @param	event		イベントポインタ
 *
 * @retval  BOOL		TRUE：イベント終了	FALSE：イベント継続
 */
//==============================================================================
static BOOL CamMoveWaitEvt(GMEVENT_CONTROL * event)
{
	FIELDSYS_WORK * fsys = FieldEvent_GetFieldSysWork(event);
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	if ( CamMove_CheckFinished(work->CamCntPtr) ){
		//カメラ情報をデバッグ出力
		{
			VecFx32 look_at = GFC_GetLookTarget(fsys->camera_ptr);
			const VecFx32 *bind = GFC_GetBindTargetVecPtr(fsys->camera_ptr);
			CAMERA_ANGLE ang = GFC_GetCameraAngle(fsys->camera_ptr);
			OS_Printf("dis:%x\n",GFC_GetCameraDistance(fsys->camera_ptr));
			OS_Printf("ang:%x,%x,%x\n",ang.x, ang.y, ang.z);
			OS_Printf("per:%x\n",GFC_GetCameraPerspWay(fsys->camera_ptr));
			OS_Printf("near_far:%d,%d\n",
					GFC_GetCameraNear(fsys->camera_ptr)/FX32_ONE, GFC_GetCameraFar(fsys->camera_ptr)/FX32_ONE);
			OS_Printf("shift:%x,%x,%x\n",look_at.x-bind->x, look_at.y-bind->y, look_at.z-bind->z);
		}
		return TRUE;
	}
	return FALSE;
}

//==============================================================================
/**
 * 伝説ポケ降臨イベントコール
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_CallDescendPokeEvt(FIELDSYS_WORK * fsys)
{
	FLD_DESCEND_WORK *fdw;
	fdw = sys_AllocMemoryLo(HEAPID_FIELD, sizeof(FLD_DESCEND_WORK));
	//ルギア・ホウオウどちらのデモかをセット(バージョンで判定)
	fdw->Version = CasetteVersion;
#ifdef PM_DEBUG
	if (DebugLegFldDemoFlg == 1){
		fdw->Version = VERSION_GOLD;
	}else if (DebugLegFldDemoFlg == 2){
		fdw->Version = VERSION_SILVER;
	}
#endif

	FieldEvent_Call(fsys->event, DescendPokeEvt, fdw);
}

//==============================================================================
/**
 * 伝説ポケ降臨イベント
 *
 * @param	event		イベントポインタ
 *
 * @retval  BOOL		TRUE：イベント終了	FALSE：イベント継続
 */
//==============================================================================
static BOOL DescendPokeEvt(GMEVENT_CONTROL * event)
{
	int obj_id;
	int monsno;
	int wing_se_wait;
	int wing_se;
	FIELD_OBJ_PTR fldobj;
	FIELDSYS_WORK * fsys = FieldEvent_GetFieldSysWork(event);
	FLD_DESCEND_WORK * fdw = FieldEvent_GetSpecialWork(event);
	int *seq = FieldEvent_GetSeqWork(event);

	if (fdw->Version == VERSION_SILVER){
		obj_id = D40R0107_RUGIA_01;
		monsno = MONSNO_RUGIA;
		wing_se_wait = RUGIA_WING_SE_WAIT;
		wing_se = SEQ_SE_GS_RUGIA_HABATAKI;
	}else{
		obj_id = D17R0110_HOUOU_01;
		monsno = MONSNO_HOUOU;
		wing_se_wait = HOUOU_WING_SE_WAIT;
		wing_se = SEQ_SE_GS_HOUOU_HABATAKI;
	}

	fldobj = FieldOBJSys_OBJIDSearch( fsys->fldobjsys, obj_id );

	GF_ASSERT(fldobj != NULL);

	switch(*seq){
	case 0:
		{
			int heap = HEAPID_FIELD;
			// アロケーター作成
			sys_InitAllocator( &fdw->Allocator, heap, 32 );
			//モデルロード
			FLD_3DObjMdlLoad(&fdw->Mdl,ARC_FLD_DEMO_GRA , NARC_fld_demo_ef_lre1_nsbmd, heap);
			//アニメデータロード
			FLD_3DObjAnmLoad(	&fdw->Anm[0],&fdw->Mdl,ARC_FLD_DEMO_GRA,NARC_fld_demo_ef_lre1_nsbca,
								heap, &fdw->Allocator );
			FLD_3DObjAnmLoad(	&fdw->Anm[1],&fdw->Mdl,ARC_FLD_DEMO_GRA,NARC_fld_demo_ef_lre1_nsbma,
								heap, &fdw->Allocator );
			FLD_3DObjAnmLoad(	&fdw->Anm[2],&fdw->Mdl,ARC_FLD_DEMO_GRA,NARC_fld_demo_ef_lre1_nsbtp,
								heap, &fdw->Allocator );
			//描画オブジェクト初期化
			FLD_3DObjInit( &fdw->Obj, &fdw->Mdl );
			//アニメをリンク
			FLD_3DObjAddAnm( &fdw->Obj, &fdw->Anm[0] );
			FLD_3DObjAddAnm( &fdw->Obj, &fdw->Anm[1] );
			FLD_3DObjAddAnm( &fdw->Obj, &fdw->Anm[2] );
			//描画フラグ設定	(非表示)
			FLD_3DObjSetDraw( &fdw->Obj, FALSE );
			//フレームセット
			SetAnmFrame(fdw->Anm, SHINE_ANM_NUM, 0);
			//座標セット
			{
				VecFx32 vec;
				FieldOBJ_VecPosGet( Player_FieldOBJGet( fsys->player ), &vec );
				if (fdw->Version == VERSION_GOLD){
					vec.x += (GOL_EFF_POS_X * FX32_ONE);
					vec.y += (GOL_EFF_POS_Y * FX32_ONE);
					vec.z += (GOL_EFF_POS_Z * FX32_ONE);
				}else{
					vec.x += (SIL_EFF_POS_X * FX32_ONE);
					vec.y += (SIL_EFF_POS_Y * FX32_ONE);
					vec.z += (SIL_EFF_POS_Z * FX32_ONE);
				}
				FLD_3DObjSetMatrix( &fdw->Obj, vec.x, vec.y, vec.z );
			}
		}
		(*seq)++;
		break;
	case 1:
		{
			VecFx32 vec;
			//ポケの高さ取得を解除。所定の高さに移動
			FieldOBJ_VecPosGet( fldobj, &vec );
			//移動前Y座標保存
			fdw->OrgY = vec.y;
			//上昇差分保存
			if (fdw->Version == VERSION_GOLD){
				fdw->Len = LEG_MONS_APP_YOFS_G;
			}else{
				fdw->Len = LEG_MONS_APP_YOFS_S;
			}
			//差分セット
			vec.y += fdw->Len;
			FieldOBJ_VecPosSet( fldobj, &vec );
			//ポケのバニッシュを解く
			FieldOBJ_StatusBitSet_Vanish( fldobj, FALSE );

			fdw->Wait = 0;
			fdw->WingSeMargine = 0;

			(*seq)++;
		}
		break;
	case 2:
		fdw->Wait++;
		//翼ＳＥ
		{
			if (fdw->Wait>=wing_se_wait){
				//定期的に鳴らす
				if (fdw->WingSeMargine <= 0){
					Snd_SePlay(wing_se);
					fdw->WingSeMargine = WING_SE_MARGINE;
				}
				fdw->WingSeMargine--;
			}
		}
		//移動
		{
			VecFx32 vec;
			BOOL end = FALSE;
			FieldOBJ_VecPosGet( fldobj, &vec );
			//ポケを地面まで移動
			if (fdw->Version == VERSION_GOLD){
				fdw->Len -= LEG_MONS_DOWN_SPD_G;
			}else{
				fdw->Len -= LEG_MONS_DOWN_SPD_S;
			}

			if (fdw->Len <= 0){
				fdw->Len = 0;
				end = TRUE;
			}
			vec.y = fdw->OrgY + fdw->Len;
			FieldOBJ_VecPosSet( fldobj, &vec );
			if (end){
				fdw->Wait = 0;
				(*seq)++;
			}
		}
		break;
	case 3:
		//しばらくパタパタさせる
		fdw->Wait++;
		if (fdw->Wait>=DESCEND_WAIT1){
			//アニメ切り替え
			FieldOBJ_DrawStatusSet( fldobj, 1 );
			fdw->Wait = 0;
			(*seq)++;
		}
		break;
	case 4:
		fdw->Wait++;
		if (fdw->Wait>=SHINE_WAIT){
			//発光開始
			FLD_3DObjSetDraw( &fdw->Obj, TRUE );
			//鳴き声
			Snd_PMVoicePlay(monsno,0);
			fdw->Frame = 0;
			fdw->Wait = 0;
			(*seq)++;
		}
		break;
	case 5:
		{
			BOOL rc;
			rc = AnimeNoLoop( fdw->Anm, SHINE_ANM_NUM );
			fdw->Frame++;
			if (rc && (fdw->Frame >= SHINE_FRAME)){
				//ループアニメに戻す
				FieldOBJ_DrawStatusSet( fldobj, 0 );
				fdw->Wait = 0;
				(*seq)++;
			}
			//描画
			FLD_3DObjDraw( &fdw->Obj );
		}
		break;
	case 6:
		//少しパタパタ
		fdw->Wait++;
		if (fdw->Wait>=DESCEND_WAIT2){
			(*seq)++;
		}
		break;
	case 7:	//終了
		//アニメデータ破棄
		FLD_3DObjAnmDelete( &fdw->Anm[2], &fdw->Allocator);
		FLD_3DObjAnmDelete( &fdw->Anm[1], &fdw->Allocator);
		FLD_3DObjAnmDelete( &fdw->Anm[0], &fdw->Allocator);
		//モデルデータ破棄
		FLD_3DObjMdlDelete( &fdw->Mdl);

		sys_FreeMemoryEz(fdw);
		return TRUE;
	}

	return FALSE;
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？再生
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_StartWeatherEffect(FIELDSYS_WORK * fsys)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	if (work->Version == VERSION_SILVER){
		StartWeatherEffectRugia(fsys);
	}else{
		StartWeatherEffectHouou(fsys);
	}
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？再生
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
static void StartWeatherEffectRugia(FIELDSYS_WORK * fsys)
{
	int heap = HEAPID_FIELD;
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//ワークにアクセス
	FLD_LEG_DEMO_WORK *wk = FLDMAPFUNC_GetFreeWork(work->Bell);
	//ルギアワーク
	RUGIA_WORK *ptr = &wk->RugiaWork;
	//データセットアップ
	//モデルロード
	FLD_3DObjMdlLoad(&ptr->EffMdl,ARC_FLD_DEMO_GRA , NARC_fld_demo_nami_nsbmd, heap);
	//アニメデータロード
	FLD_3DObjAnmLoad(&ptr->EffAnm[0],&ptr->EffMdl,ARC_FLD_DEMO_GRA,NARC_fld_demo_nami_nsbca,
		heap, &wk->Allocator );
	FLD_3DObjAnmLoad(&ptr->EffAnm[1],&ptr->EffMdl,ARC_FLD_DEMO_GRA,NARC_fld_demo_nami_nsbta,
		heap, &wk->Allocator );

	//描画オブジェクト初期化
	FLD_3DObjInit( &ptr->EffObj, &ptr->EffMdl );
	//アニメをリンク
	FLD_3DObjAddAnm( &ptr->EffObj, &ptr->EffAnm[0] );
	FLD_3DObjAddAnm( &ptr->EffObj, &ptr->EffAnm[1] );
	//描画フラグ設定	(表示)
	FLD_3DObjSetDraw( &ptr->EffObj, TRUE );
	//フレームセット
	SetAnmFrame(ptr->EffAnm, RUGIA_EFF_ANM_NUM, 0);
	//表示位置セット
	{
		VecFx32 vec;
		//主人公の位置に表示
		FieldOBJ_VecPosGet( Player_FieldOBJGet( fsys->player ), &vec );
		FLD_3DObjSetMatrix( &ptr->EffObj, vec.x, vec.y, vec.z );
	}

	//TCB生成
	wk->EffTcb = TCB_Add(RugiaEffectTcb, wk, 0);

}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？再生		ホウオウ版
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
static void StartWeatherEffectHouou(FIELDSYS_WORK * fsys)
{
	u8 i;
	int heap = HEAPID_FIELD;
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//ワークにアクセス
	FLD_LEG_DEMO_WORK *wk = FLDMAPFUNC_GetFreeWork(work->Bell);

	HOUOU_WORK* ptr = &wk->HououWork;
	ptr->bgl = fsys->bgl;

	//データセットアップ
	//スクリーンロード
	for(i=0;i<HOUOU_SCRN_NUM;i++){
		ptr->BgArc1[i] = ArcUtil_ScrnDataGet(ARC_FLD_DEMO_GRA, HououBG1Arc[i],
						FALSE, &ptr->ScrnData1[i], heap);
		ptr->BgArc2[i] = ArcUtil_ScrnDataGet(ARC_FLD_DEMO_GRA, HououBG2Arc[i],
						FALSE, &ptr->ScrnData2[i], heap);
	}
	GF_BGL_ScreenBufSet( ptr->bgl, GF_BGL_FRAME2_M,
			ptr->ScrnData1[0]->rawData, ptr->ScrnData1[0]->szByte );
	GF_BGL_ScreenBufSet( ptr->bgl, GF_BGL_FRAME3_M,
			ptr->ScrnData2[0]->rawData, ptr->ScrnData2[0]->szByte );

	GF_BGL_ScrPalChange( ptr->bgl, GF_BGL_FRAME2_M, 0, 0, 32, 32, FLD_WEATHER_PAL );
	GF_BGL_ScrPalChange( ptr->bgl, GF_BGL_FRAME3_M, 0, 0, 32, 32, FLD_WEATHER_PAL );

	//キャラデータロード
	ArcUtil_BgCharSet(ARC_FLD_DEMO_GRA, NARC_fld_demo_hou_demobg_ncgr,
						ptr->bgl, GF_BGL_FRAME2_M, 0, 0, FALSE, heap);
	ArcUtil_BgCharSet(ARC_FLD_DEMO_GRA, NARC_fld_demo_hou_demobg_ncgr,
						ptr->bgl, GF_BGL_FRAME3_M, 0, 0, FALSE, heap);
	//パレットロード
	ArcUtil_PalSet( ARC_FLD_DEMO_GRA, NARC_fld_demo_hou_demobg_nclr,
						PALTYPE_MAIN_BG, FLD_WEATHER_PAL*32, 32, heap );
	//TCB生成
	wk->EffTcb = TCB_Add(HououEffectTcb, wk, 0);

	GF_BGL_LoadScreenV_Req(ptr->bgl, GF_BGL_FRAME2_M);
	GF_BGL_LoadScreenV_Req(ptr->bgl, GF_BGL_FRAME3_M);

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_ON );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG3, VISIBLE_ON );

	//フレーム初期化
	ptr->Frame = 0;
	ptr->ScrNo = 0;
	//BGプライオリティ変更
	G2_SetBG2Priority(0);
	G2_SetBG3Priority(1);
	G2_SetBG0Priority(2);
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？終了
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_EndWeatherEffect(FIELDSYS_WORK * fsys)
{
	DEMO_PARENT_WORK *work = (DEMO_PARENT_WORK *)fsys->fldmap->Work;
	//ワークにアクセス
	FLD_LEG_DEMO_WORK *wk = FLDMAPFUNC_GetFreeWork(work->Bell);
	//TCB削除
	TCB_Delete(wk->EffTcb);
	wk->EffTcb = NULL;

	if (work->Version == VERSION_SILVER){
		EndWeatherEffectRugia(wk);
	}else{
		EndWeatherEffectHouou(wk);
	}
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？終了	ルギア
 *
 * @param	wk		デモワーク
 *
 * @retval  none
 */
//==============================================================================
static void EndWeatherEffectRugia(FLD_LEG_DEMO_WORK *wk)
{
	//ルギアワーク
	RUGIA_WORK *ptr = &wk->RugiaWork;
	//データ解放
	FLD_3DObjAnmDelete( &ptr->EffAnm[1], &wk->Allocator);
	FLD_3DObjAnmDelete( &ptr->EffAnm[0], &wk->Allocator);
	//モデルデータ破棄
	FLD_3DObjMdlDelete( &ptr->EffMdl);
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？終了	ホウオウ
 *
 * @param	wk			ワークポインタ
 *
 * @retval  none
 */
//==============================================================================
static void EndWeatherEffectHouou(FLD_LEG_DEMO_WORK *wk)
{
	u8 i;
	HOUOU_WORK* ptr = &wk->HououWork;
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_OFF );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG3, VISIBLE_OFF );
	for(i=0;i<HOUOU_SCRN_NUM;i++){
		//BGアーカイブ解放
		sys_FreeMemoryEz(ptr->BgArc1[i]);
		sys_FreeMemoryEz(ptr->BgArc2[i]);
	}
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？TCB	ルギア
 *
 * @param	tcb		TCBポインタ
 * @param	work	ワーク
 *
 * @retval  none
 */
//==============================================================================
static void RugiaEffectTcb(TCB_PTR tcb, void *work)
{
	FLD_LEG_DEMO_WORK *wk = work;
	//ルギアワーク
	RUGIA_WORK *ptr = &wk->RugiaWork;

	AnimeLoop(ptr->EffAnm, RUGIA_EFF_ANM_NUM);

	FLD_3DObjDraw( &ptr->EffObj );
}

//==============================================================================
/**
 * 伝説ポケ天候エフェクト？TCB　ホウオウ
 *
 * @param	tcb		TCBポインタ
 * @param	work	ワーク
 *
 * @retval  none
 */
//==============================================================================
static void HououEffectTcb(TCB_PTR tcb, void *work)
{
	FLD_LEG_DEMO_WORK *wk = work;
	HOUOU_WORK* ptr = &wk->HououWork;
	//スクリーン書き換え
	ptr->Frame++;
	if (ptr->Frame >= HOUOU_SCRN_BG_ANM_FRAME){
		ptr->Frame = 0;
		ptr->ScrNo++;
		if (ptr->ScrNo >= HOUOU_SCRN_NUM){
			ptr->ScrNo = 0;
		}
		//書き換え
		GF_BGL_ScrWriteFree(ptr->bgl, GF_BGL_FRAME2_M,
				0, 0, 32, 32,
				&ptr->ScrnData1[ptr->ScrNo]->rawData,
				0, 0, 32, 32 );
		GF_BGL_ScrWriteFree(ptr->bgl, GF_BGL_FRAME3_M,
				0, 0, 32, 32,
				&ptr->ScrnData2[ptr->ScrNo]->rawData,
				0, 0, 32, 32 );
		GF_BGL_ScrPalChange( ptr->bgl, GF_BGL_FRAME2_M, 0, 0, 32, 32, FLD_WEATHER_PAL );
		GF_BGL_ScrPalChange( ptr->bgl, GF_BGL_FRAME3_M, 0, 0, 32, 32, FLD_WEATHER_PAL );
		GF_BGL_LoadScreenV_Req(ptr->bgl, GF_BGL_FRAME2_M);
		GF_BGL_LoadScreenV_Req(ptr->bgl, GF_BGL_FRAME3_M);
	}
	//BGスクロール
	ptr->XOfs1--;
	ptr->XOfs2++;
	ptr->YOfs--;
	GF_BGL_ScrollReq( ptr->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, ptr->XOfs1 );
	GF_BGL_ScrollReq( ptr->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, ptr->YOfs );
	GF_BGL_ScrollReq( ptr->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_SET, ptr->XOfs2 );
	GF_BGL_ScrollReq( ptr->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, ptr->YOfs );
}



//==============================================================================
/**
 * 伝説系アプリデモ終了後のフィールドデモメモリの確保と初期化
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_InitAfterApp(FIELDSYS_WORK * fsys)
{
	DEMO_AF_APP_PARENT_WORK *work;
	//フィールド汎用ワークにメモリをアロケーション
	fsys->fldmap->Work = sys_AllocMemoryLo(HEAPID_FIELD, sizeof(DEMO_AF_APP_PARENT_WORK));
	work = (DEMO_AF_APP_PARENT_WORK *)fsys->fldmap->Work;

	//バージョン
	work->Version = CasetteVersion;
#ifdef PM_DEBUG
	if (DebugLegFldDemoFlg == 1){
		work->Version = VERSION_GOLD;
	}else if (DebugLegFldDemoFlg == 2){
		work->Version = VERSION_SILVER;
	}
#endif

	//金バージョンの場合はアプリデモ復帰がフリームーブのカメラアングルになっているので、設定不要
	if (work->Version == VERSION_GOLD){
		GF_ASSERT_MSG(0,"ERROR InitAfterApp 金バージョンでは不要の処理のはずなのにコールされました\n");
		return;
	}

	//現在カメラ情報の保存
	work->Distance = GFC_GetCameraDistance(fsys->camera_ptr);
	work->Angle = GFC_GetCameraAngle(fsys->camera_ptr);
	{
		VecFx32 look_at = GFC_GetLookTarget(fsys->camera_ptr);
		const VecFx32 *bind = GFC_GetBindTargetVecPtr(fsys->camera_ptr);
		VEC_Subtract(&look_at, bind, &work->Shift);
	}
	work->PerspWay = GFC_GetCameraPerspWay(fsys->camera_ptr);
	work->Near = GFC_GetCameraNear(fsys->camera_ptr);
	work->Far = GFC_GetCameraFar(fsys->camera_ptr);

	//カメラをセット
	//距離
	GFC_SetCameraDistance(CameraDataRugia[4].Distance, fsys->camera_ptr);
	//アングル変更
	GFC_SetCameraAngleRev(&CameraDataRugia[4].Angle, fsys->camera_ptr);
	//パース変更
	GFC_SetCameraPerspWay(CameraDataRugia[4].PerspWay, fsys->camera_ptr);
	//シフト
	GFC_ShiftCamera( &CameraShiftRugia[4], fsys->camera_ptr);
	//ニア・ファー
	GFC_SetCameraClip(150*FX32_ONE, 1700*FX32_ONE, fsys->camera_ptr);

}

//==============================================================================
/**
 * 伝説系アプリデモ終了後のフィールドデモメモリの解放
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_EndAfterApp(FIELDSYS_WORK * fsys)
{
	DEMO_AF_APP_PARENT_WORK *work = (DEMO_AF_APP_PARENT_WORK *)fsys->fldmap->Work;
	//金バージョンの場合はアプリデモ復帰がフリームーブのカメラアングルになっているので、設定不要
	if (work->Version == VERSION_GOLD){
		GF_ASSERT_MSG(0,"ERROR:EndAfterApp 金バージョンでは不要の処理のはずなのにコールされました\n");
	}
	//フィールド汎用ワークにメモリを解放
	sys_FreeMemoryEz(fsys->fldmap->Work);
	fsys->fldmap->Work = NULL;
}

//==============================================================================
/**
 * デモ終了カメラ位置戻し
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @retval  none
 */
//==============================================================================
void FldLegDemo_ReturnCamera(FIELDSYS_WORK * fsys)
{
	CAMERA_MOVE_PARAM param;
	DEMO_AF_APP_PARENT_WORK *work = (DEMO_AF_APP_PARENT_WORK *)fsys->fldmap->Work;
	//金バージョンの場合はアプリデモ復帰がフリームーブのカメラアングルになっているので、設定不要
	if (work->Version == VERSION_GOLD){
		GF_ASSERT_MSG(0,"ERROR:ReturnCamera 金バージョンでは不要の処理のはずなのにコールされました\n");
		return;
	}

	work->CamCntPtr = CamMove_Init(HEAPID_FIELD, fsys->camera_ptr);

	param.Angle = work->Angle.x;
	param.PerspWay = work->PerspWay;
	param.Length = work->Shift;
	param.Distance = work->Distance;
	CamMove_Request(work->CamCntPtr, &param, DEMO_CAM_RETURN_SYNC);

	//イベントコール
	FieldEvent_Call(fsys->event, ReturnCameraEvt, fsys);
}

//==============================================================================
/**
 * カメラ戻しイベント
 *
 * @param	event		イベントポインタ
 *
 * @retval  BOOL		TRUE：イベント終了	FALSE：イベント継続
 */
//==============================================================================
static BOOL ReturnCameraEvt(GMEVENT_CONTROL * event)
{
	FIELDSYS_WORK * fsys = FieldEvent_GetSpecialWork(event);
	DEMO_AF_APP_PARENT_WORK *work = (DEMO_AF_APP_PARENT_WORK *)fsys->fldmap->Work;
	CAM_MOV_CNT_PTR camCntPtr = work->CamCntPtr;

	//カメラ動き終わったか？
	if ( CamMove_CheckFinished(camCntPtr) ){
		//カメラコントローラ解放
		CamMove_Delete(camCntPtr);

		//ニア・ファーをマップの設定に戻す
		GFC_SetCameraClip(work->Near, work->Far, fsys->camera_ptr);
		return TRUE;
	}
	return FALSE;
}